Page({
  data: {
    cateItems: [
      {
        cate_id: 1,
        cate_name: "艾草制品",
        ishaveChild: true,
        children:
          [
            {
              child_id: 1,
              price: 40,
              name: '正品艾条',
              image: "../../static/goods_items/1item1/goods1.png",
              description: "三年陈蕲手工桑皮纸艾条",
              sale_num: 125,
              imgUrls: [
                "../../static/goods_items/1item1/goods1.png",
                "../../static/goods_items/1item1/goods1_about1.png",
                "../../static/goods_items/1item1/goods1_about2.png",
                "../../static/goods_items/1item1/goods1_about3.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/1item1/detail1/goods1_detail1.png",
                "../../static/goods_items/1item1/detail1/goods1_detail2.png",
                "../../static/goods_items/1item1/detail1/goods1_detail3.png",
                "../../static/goods_items/1item1/detail1/goods1_detail4.png",
                "../../static/goods_items/1item1/detail1/goods1_detail5.png",
                "../../static/goods_items/1item1/detail1/goods1_detail6.png"
              ],
            },
            {
              child_id: 2,
              price: 38,
              name: '散装艾绒',
              image: "../../static/goods_items/1item2/goods2.png",
              description: "蕲艾艾绒艾草艾灸艾柱艾条原料",
              sale_num: 500,
              imgUrls: [
                "../../static/goods_items/1item2/goods2.png",
                "../../static/goods_items/1item2/goods2_about1.png",
                "../../static/goods_items/1item2/goods2_about2.png",
                "../../static/goods_items/1item2/goods2_about3.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/1item2/detail2/goods2_detail1.png",
                "../../static/goods_items/1item2/detail2/goods2_detail2.png",
                "../../static/goods_items/1item2/detail2/goods2_detail3.png",
              ],
            }
          ]
      },
      {
        cate_id: 2,
        cate_name: "装饰艾草",
        ishaveChild: true,
        children:
          [
            {
              child_id: 3,
              price: 10,
              name: '艾叶饼',
              image: "../../static/goods_items/2item1/goods3.png",
              description: "天然野生蕲艾艾叶饼",
              sale_num: 2000,
              imgUrls: [
                "../../static/goods_items/2item1/goods3.png",
                "../../static/goods_items/2item1/goods3_about1.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/2item1/detail3/goods3_detail1.png",
                "../../static/goods_items/2item1/detail3/goods3_detail2.png",
                "../../static/goods_items/2item1/detail3/goods3_detail3.png",
                "../../static/goods_items/2item1/detail3/goods3_detail4.png",
              ],
            }
          ]
      },
      {
        cate_id: 3,
        cate_name: "理疗艾草",
        ishaveChild: true,
        children:
          [
            {
              child_id: 4,
              price: 38,
              name: '食用艾草叶',
              image: "../../static/goods_items/3item1/goods4.png",
              description: "“食用艾草叶”采取国际先进加压蒸青技术，手摘清明时期的鲜嫩艾叶，选用可食用小叶艾叶，配以专业干燥技术，最大限度的保留了艾叶的营养价值，生产的每步骤皆有相应的部门严格监控。专业化的生产使该产品兼顾色香味的同时充分发挥艾草的功效。",
              sale_num: 500,
              imgUrls: [
                "../../static/goods_items/3item1/goods4.png",
                "../../static/goods_items/3item1/goods4_about1.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/3item1/detail4/goods4_detail1.png",
                "../../static/goods_items/3item1/detail4/goods4_detail2.png",
              ],
            },
            {
              child_id: 5,
              price: 38,
              name: '艾草复方精油',
              image: "../../static/goods_items/3item2/goods5.png",
              description: "蕲艾精油，纯自然复方艾油 全是推背 疏通经络",
              sale_num: 750,
              imgUrls: [
                "../../static/goods_items/3item2/goods5.png",
                "../../static/goods_items/3item2/goods5_about1.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/3item2/detail5/goods5_detail1.png",
                "../../static/goods_items/3item2/detail5/goods5_detail2.png",
                "../../static/goods_items/3item2/detail5/goods5_detail3.png",
              ],
            },
            {
              child_id: 6,
              price: 68,
              name: '艾草宫颈枕',
              image: "../../static/goods_items/3item3/goods6.png",
              description: "将五行原料科学配比晾晒过后放入枕芯同时结合中医古老灸法的原理，将艾草枕头发挥最大的疗效。依据中医“内病外治”的理论，药效通过皮肤毛孔透皮吸收，从而起到祛寒护阳，平衡气血调节阴阳，增强自身免疫力，保健养生的功效。有效提升睡眠深度，能够充分改善脑部供氧，消除大脑疲劳，调节神经系统功能。并且可以杀菌、抗病毒。可清脑、明目、安神、改善睡眠，同时能疏通脑血管，预防脑血栓发生。",
              sale_num: 1500,
              imgUrls: [
                "../../static/goods_items/3item3/goods6.png",
                "../../static/goods_items/3item3/goods6_about1.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/3item3/detail6/goods6_detail1.png",
              ],
            },
            {
              child_id: 7,
              price: 128,
              name: '坐灸仪',
              image: "../../static/goods_items/3item4/goods7.png",
              description: "真不错",
              sale_num: 125,
              imgUrls: [
                "../../static/goods_items/3item4/goods7.png",
                "../../static/goods_items/3item4/goods7_about1.png",
                "../../static/goods_items/3item4/goods7_about2.png",
              ],
              //商品详情图
              detailImg: [
                "../../static/goods_items/3item4/detail7/goods7_detail1.png",
                "../../static/goods_items/3item4/detail7/goods7_detail2.png",
              ],
            }
          ]
      }
    ],
    //导航栏
    curNav: 1,
    curIndex: 0,
    //商品
    goodsIndex: 0,
    goodsId: 1
  },

  //事件处理函数  
  switchRightTab: function (e) {
    // 获取item项的id，和数组的下标值  
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    // 把点击到的某一项，设为当前index  
    this.setData({
      curNav: id,
      curIndex: index
    })
    console.log("当前的分类页" + index);
  },
  //点击商品跳转到商品详情页
  switchItemDetail: function (e) {
    //获取商品的索引
    let item = e.currentTarget.dataset.item
    // console.log(e.currentTarget.dataset.item.child_id);
    // console.log(item);
    //自定义一个商品对象，然后传给商品详情页
    let obj = {}
    obj.id = item.child_id
    obj.name = item.name
    obj.price = item.price
    obj.imgUrls = item.imgUrls
    obj.detailImg = item.detailImg
    obj.description = item.description
    obj.sale_num = item.sale_num
    console.log(obj);
    //缓存到本地
    wx.setStorageSync('goods_obj', obj);
    // < !--url="/pages/item_detail/item_detail" -- >
    wx.navigateTo({
      url: '/pages/item_detail/item_detail'
    });
  }
})  